<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Student extends CI_Controller {

	public function __construct() {
		parent::__construct();
		if ($this->session->userdata('user')->site_role != 'student')
			redirect('/');

		if ($this->session->userdata('user')->wizard_status == 'active')
			redirect('new_user');
	}

	public function index() {
		$this->load->model('rank_model', '', TRUE);
		$this->load->model('event_model', '', TRUE);
		$this->load->model('company_model', '', TRUE);
		$data['overallRank'] = $this->rank_model->get_overall_rank($this->session->userdata('user')->user_id);
		$data['groupRank'] = $this->rank_model->get_group_rank($this->session->userdata('user')->user_id, 'score');
		$data['events'] = $this->event_model->get_user_events($this->session->userdata('user')->user_id);
		$data['companies'] = $this->company_model->get_user_companies($this->session->userdata('user')->user_id);
		$this->load->view('master', $data);
	}

	public function groups() {
		$this->load->model('rank_model', '', TRUE);
		$data['overallRank'] = $this->rank_model->get_overall_rank($this->session->userdata('user')->user_id);
		$data['groupRank'] = $this->rank_model->get_group_rank($this->session->userdata('user')->user_id);
		$this->load->view('master', $data);
	}

	public function group_search() {
		if (!$this->input->post()) redirect('/student');

		$this->load->model('group_model', '', TRUE);
		$data['groupList'] = $this->group_model->search_groups($this->input->post('searchTerm'));
		$this->load->view('master', $data);
	}

	public function group_details($groupType, $groupID) {
		$this->load->model('group_model', '', TRUE);
		$this->load->model('event_model', '', TRUE);
		$data['group'] = $this->group_model->get_group_details($groupType, $groupID);
		$data['members'] = $this->group_model->get_top_ten($groupType, $groupID);
		$data['events'] = $this->event_model->get_group_events($groupID);
		$this->load->view('master', $data);
	}

	public function events() {
		$this->load->model('event_model', '', TRUE);
		$data['events'] = $this->event_model->get_user_events($this->session->userdata('user')->user_id);
		$this->load->view('master', $data);		
	}

	public function event_search() {
		if (!$this->input->post()) redirect('/student');

		$this->load->model('event_model', '', TRUE);
		$data['eventList'] = $this->event_model->search_events($this->input->post('searchTerm'));
		$this->load->view('master', $data);
	}

	public function event_details($eventID) {
		$this->load->model('event_model', '', TRUE);
		$data['event'] = $this->event_model->get_event_details($eventID);
		//$data['members'] = $this->event_model->get_checkedin($eventID);
		$this->load->view('master', $data);
	}

	public function companies() {
		$this->load->model('company_model', '', TRUE);
		$data['companies'] = $this->company_model->get_user_companies($this->session->userdata('user')->user_id);
		$this->load->view('master', $data);
	}

	public function company_search() {
		if (!$this->input->post()) redirect('/student');

		$this->load->model('company_model', '', TRUE);
		$data['companies'] = $this->company_model->search_companies($this->input->post('searchTerm'));
		$this->load->view('master', $data);
	}

	public function company_details($companyID) {
		$this->load->model('company_model', '', TRUE);
		$data['company'] = $this->company_model->get_company_details($companyID);
		$this->load->view('master', $data);
	}

	public function profile() {
		$this->load->model('user_model', '', TRUE);
		$data['user'] = $this->user_model->get_user_details($this->session->userdata('user')->user_id);
		$this->load->view('master', $data);
	}

}